<%--
  Created by IntelliJ IDEA.
  User: 13585
  Date: 2020/12/23
  Time: 21:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
<div id="regform">
    <table class="layui-table">
        <colgroup>
            <col width="50">
            <col width="100">
        </colgroup>
        <thead>

        <tr>
            <th>编号</th>
            <th>申请人</th>
            <th>团队名称</th>
            <th>团队负责人</th>
            <th>所在单位</th>
            <th>职工号</th>
            <th>地址</th>
            <th>手机号</th>
            <th>办公电话</th>
            <th>Email</th>
            <th>主要用途</th>
            <th>备注</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${listPage.list}" var="regformList" varStatus="vs">
            <tr>
                <td>${vs.count}</td>
                <td>${regformList.name}</td>
                <td>${regformList.regform.teamname}</td>
                <td>${regformList.regform.teampeo}</td>
                <td>${regformList.regform.unit}</td>
                <td>${regformList.regform.empnum}</td>
                <td>${regformList.regform.address}</td>
                <td>${regformList.regform.phone}</td>
                <td>${regformList.regform.telnum}</td>
                <td>${regformList.regform.email}</td>
                <td>${regformList.regform.purpose}</td>
                <td>${regformList.regform.remarks}</td>
                <td><span id="status${vs.count}" class="${regformList.style}">${regformList.status}</span></td>
                <td>
                    <div class="layui-btn-group">
                        <button onclick="statusChange(${vs.count},${regformList.uid},1)"  class="layui-btn layui-btn-xs">通过</button>
                        <button onclick="statusChange(${vs.count},${regformList.uid},-1)" class="layui-btn layui-btn-xs">拒绝</button>
                    </div>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<div id="page"></div>
<script type="text/javascript" src="layui/layui.js"></script>
<script>
    function statusChange(count,uid,status) {
        let ajax;
        if (window.XMLHttpRequest){
            ajax = new XMLHttpRequest();
        }else {
            ajax = new ActiveXObject("Microsoft.XMLHttp");
        }
        ajax.onreadystatechange = function () {
            if(ajax.readyState == 4 && ajax.status){
                let result = ajax.responseText;
                if (result == "ok"){
                    let span = document.getElementById("status"+count);
                    switch (status) {
                        case 1 : {
                            span.className = "status-pass";
                            span.innerHTML = "以通过";
                            break;
                        }
                        case -1 : {
                            span.className = "status-refuse";
                            span.innerHTML = "未通过";
                        }
                    }
                }
            }
        }
        ajax.open("GET","changeStatus?id="+uid+"&status="+status);
        ajax.send();
    }
</script>
<script>
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
            ,count: ${listPage.totalCount} //数据总数，从服务端得到
            ,limit: ${listPage.rows} //每页显示10条
            ,layout: ['prev','page','next','count']
            ,curr: ${listPage.currentPage} //获取起始页
            ,jump: function(obj,first){
                if (!first) {
                    var currentPage=obj.curr;
                    window.location.href="${pageContext.request.contextPath}/back/applyList?currentPage="+currentPage;//跳转链接
                }
            }
        });
    });
</script>

</body>
</html>
